﻿using System;
using System.Web;
using Microsoft.Practices.Unity;
using TSharp.Core.Osgi;
using TSharp.Core.Osgi.Internal;

namespace TSharp.Core.Unity
{
    partial class UnityServiceSituation
    {
        internal IUnityContainer CreateSessionContainer()
        {
            log.Debug("创建 Session");
            IUnityContainer container = GetOrCreateRootWrapper().unity.CreateChildContainer();

            UnitySection.Configure(container, CONFIG_CONTAINER_NAME_SESSION);
            Configure(ServiceManager.SessionMap, container);
            return container;
        }

        private UnityLocatorWrapper GetOrCreateSessionWrapper()
        {
            return AopContext.GetContext().Session.GetOrAdd(CACHEKEY_SESSION_CONTAINER, key =>
             new UnityLocatorWrapper(CreateSessionContainer(), Level.SESSION)) as UnityLocatorWrapper;
        }

    }
}